5 http://blogaritmo.factorcomun.org
12 int di
[] = { +0, +0, +1, -1};
13 int dj
[] = { +1, -1, +0, +0};
21 cin
>> name
>> r
>> c
;
22 //dp[i][j] = length of longest valid path ending at position (i,j)
23 int g
[r
][c
], dp
[r
][c
];
24 queue
<pair
<int, int> > q
;
25 for (int i
=0; i
<r
; ++i
){
26 for (int j
=0; j
<c
; ++j
){
29 q
.push(make_pair(i
, j
));
34 int i
= q
.front().first
;
35 int j
= q
.front().second
;
38 for (int k
=0; k
<4; ++k
){
41 if (0 <= ni
&& ni
< r
&&
43 g
[ni
][nj
] < g
[i
][j
] &&
44 dp
[ni
][nj
] < dp
[i
][j
] + 1){
45 dp
[ni
][nj
] = dp
[i
][j
] + 1;
46 q
.push(make_pair(ni
, nj
));
51 for (int i
=0; i
<r
; ++i
){
52 best
= max(best
, *max_element(dp
[i
], dp
[i
]+c
));
55 cout
<< name
<< ": " << best
<< endl
;